package com.zzyl.controller;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.NursingLevelDTO;
import com.zzyl.service.NursingLevelService;
import com.zzyl.vo.NursingLevelVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;

@RestController
@RequestMapping("/nursingLevel")
@Api(tags = "护理等级")
public class NursingLevelController {

    @Autowired
    private NursingLevelService nursingLevelService;

    // 查询全部
    @GetMapping("/listAll")
    @ApiOperation(value = "查询全部", notes = "无需参数，获取所有护理等级，返回护理等级信息列表")
    public ResponseResult<List<NursingLevelDTO>> getAll() {
        List<NursingLevelDTO> nursingLevelDTOList = nursingLevelService.selectAll();
        return ResponseResult.success(nursingLevelDTOList);
    }

    // 新增
    @PostMapping("/insert")
    @ApiOperation(value = "新增护理等级", notes = "传入护理等级信息，返回添加结果")
    public ResponseResult add(@ApiParam(value = "护理等级信息",readOnly = true)@RequestBody NursingLevelDTO nursingLevelDTO) {
        nursingLevelService.add(nursingLevelDTO);
        return ResponseResult.success();
    }

    // 分页查询
    @GetMapping("/listByPage")
    @ApiOperation(value = "分页查询", notes = "传入页码和每页数量，返回护理等级信息列表")
    public ResponseResult<PageResponse<NursingLevelVO>> listByPage(
            @ApiParam(value = "页码",required = true,defaultValue = "1")@RequestParam Integer pageNum,
            @ApiParam(value = "每页数量",required = true,defaultValue = "10")@RequestParam Integer pageSize,
            @ApiParam(value = "护理等级名称")@RequestParam(required = false) String name,
            @ApiParam(value = "护理等级状态")@RequestParam(required = false) Integer status) {
        PageResponse<NursingLevelVO> nursingLevelPageInfo = nursingLevelService.getByPage(name, status, pageNum, pageSize);
        return ResponseResult.success(nursingLevelPageInfo);
    }

    // 根据id查询
    @GetMapping("/{id}")
    @ApiOperation(value = "根据id查询", notes = "传入护理等级id，返回护理等级信息")
    public ResponseResult<NursingLevelVO> getById(@ApiParam(value = "护理等级id",required = true)@PathVariable Long id) {
        NursingLevelVO nursingLevelVO = nursingLevelService.getById(id);
        return ResponseResult.success(nursingLevelVO);
    }

    // 修改
    @PutMapping("/update")
    @ApiOperation(value = "修改护理等级", notes = "传入护理等级信息，返回修改结果")
    public ResponseResult update(@ApiParam(value = "护理等级信息",readOnly = true)@RequestBody NursingLevelDTO nursingLevelDTO) {
        nursingLevelService.update(nursingLevelDTO);
        return ResponseResult.success();
    }

    // 删除
    @DeleteMapping("/delete/{id}")
    @ApiOperation(value = "删除护理等级", notes = "传入护理等级id，返回删除结果")
    public ResponseResult deleteById(@ApiParam(value = "护理等级id",required = true)@PathVariable Long id) {
        nursingLevelService.delete(id);
        return ResponseResult.success();
    }

    // 修改状态
    @PutMapping("/{id}/status/{status}")
    @ApiOperation(value = "修改护理等级状态", notes = "传入护理等级id和状态，返回修改结果")
    public ResponseResult updateStatus(@ApiParam(value = "护理等级id",required = true)@PathVariable Long id,
                                       @ApiParam(value = "护理等级状态",required = true)@PathVariable Integer status) {
        NursingLevelDTO nursingLevelDTO = new NursingLevelDTO();
        nursingLevelDTO.setId(id);
        nursingLevelDTO.setStatus(status);
        nursingLevelService.update(nursingLevelDTO);
        return ResponseResult.success();
    }


}